package com.azhi.srb.core;


import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import org.junit.Test;

import java.nio.file.Paths;


public class CodeGenerator {

    //自动生成代码
    //https://baomidou.com/reference/code-generator-configuration/
    @Test
    public void genCode(){
        FastAutoGenerator.create("jdbc:mysql://localhost:3306/db200921_srb_core?useUnicode=true&useSSL=false&characterEncoding=utf8", "root", "root")
                .globalConfig(builder -> builder
                        .author("azhi")
                        .enableSwagger()
                        .outputDir(Paths.get(System.getProperty("user.dir")) + "/src/main/java")
                        .commentDate("yyyy-MM-dd")
                )
                .packageConfig(builder -> builder
                        .parent("com.azhi.srb.core")
                        .entity("entity")
                        .mapper("mapper")
                        .service("service")
                        .serviceImpl("service.impl")
                        .xml("mapper.xml")
                )
                .strategyConfig(builder -> builder
                        .entityBuilder()
                        .enableLombok()
                        .naming(NamingStrategy.underline_to_camel)
                        .columnNaming(NamingStrategy.underline_to_camel)
                        .logicDeleteColumnName("is_deleted")
                        .enableRemoveIsPrefix()
                        .controllerBuilder()

                )
                .templateEngine(new FreemarkerTemplateEngine())
                .execute();
    }
}
